#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back
#define vec vector<int>

int read(){int x = 0,sgn = 1;char ch = getchar();for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);return x*sgn;}

const int N = 5e3+10;

int h[N],cnt,n,m;
db dis[N],mid;
bool vis[N],fl;
struct edge{int v,w,nxt;}e[N<<1];
void link(int x,int y,int w){e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;}

void dfs(int x){
	vis[x] = 1; if(fl) return;
	for(int i = h[x],y;i;i = e[i].nxt){
		if(dis[y = e[i].v] > dis[x] + e[i].w + mid){
			dis[y] = dis[x] + e[i].w + mid; if(vis[y]) return fl = 1,void(); dfs(y); if(fl) return;
		}
	}vis[x] = 0;
}

bool check(){memset(vis,0,sizeof vis); for(int i = 1;i <= n;i++) dis[i] = 0; fl = 0; for(int i = 1;i <= n && !fl;i++) dfs(i); return !fl;}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in+2,m = in;
	for(int i = 1;i <= m;i++){
		int u = in,v = in,a = in,b = in,c = in,d = in;
		if(u == n + 1) a = b = d = 0;
		if(c) link(v,u,a - d);
		link(u,v,b + d);
	}
	db l = 0,r = 1e9;
	for(int i = 1;i <= 50;i++){mid = (l + r) / 2; if(check()) r = mid; else l = mid;}
	printf("%.2lf\n",mid);
	return 0;
}
